home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
bipl.zip
/
PROCS.ZIP
/
RADCON.ICN
< prev
next >
Wrap
Text File
|
1992-09-28
|
1KB
|
58 lines
############################################################################
#
# File: radcon.icn
#
# Subject: Procedures for radix conversion
#
# Author: Ralph E. Griswold
#
# Date: June 10, 1988
#
###########################################################################
#
# The following procedures convert numbers from one radix to
# another. The letters from a to z are used for ``digits'' greater
# than 9. All the conversion procedures fail if the conversion can-
# not be made.
#
# exbase10(i,j) convert base-10 integer i to base j
#
# inbase10(s,i) convert base-i integer s to base 10
#
# radcon(s,i,j) convert base-i integer s to base j
#
# Limitation:
#
# The maximum base allowed is 36.
#
############################################################################
procedure exbase10(i,j)
static digits
local s, d, sign
initial digits := &digits || &lcase
if i = 0 then return 0
if i < 0 then {
sign := "-"
i := -i
}
else sign := ""
s := ""
while i > 0 do {
d := i % j
if d > 9 then d := digits[d + 1]
s := d || s
i /:= j
}
return sign || s
end
procedure inbase10(s,i)
if s[1] == "-" then return "-" || integer(i || "r" || s[2:0])
else return integer(i || "r" || s)
end
procedure radcon(s,i,j)
return exbase10(inbase10(s,i),j)
end